import { useSelector, useDispatch } from 'react-redux'

// 获取 store --- state
export const useStoreState = (store) => {
  if (!store?.name) {
    throw new Error('useStoreState: please enter store')
  }
  return useSelector(
    (state) => state[store.name]
  )
}

// 获取 store --- action
export const useStoreAction = (fn) => {
  const dispatch = useDispatch()
  return (params) => dispatch(fn(params))
}
